home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / DIZZY / SRC / EDIT.C < prev    next >
Text File  |  1991-10-03  |  3KB  |  155 lines

  1. /*
  2. >>    Dizzy 1.0 Edit.c
  3. >>
  4. >>    A digital circuit simulator & design program for the X Window System
  5. >>
  6. >>    Copyright 1990 Juri Munkki, all rights reserved
  7. */
  8.  
  9. #include "dizzy.h"
  10.  
  11. /*
  12. >>    This routine is called when the user clicks in the edit area.
  13. >>    The main purpose is to decide which tool to use and how to
  14. >>    manage the use of that tool.
  15. */
  16. void    DoEditClick()
  17. {
  18.     int             WhichButton;
  19.     ToolSelection    *sel;
  20.     Element         *elem;
  21.     Point            spot;
  22.     long            obtype;
  23.     int             createflag;
  24.     
  25. #ifdef    MACINTOSH
  26.     SetPort(MyWind);
  27. #endif
  28.  
  29.     if(SplashVisible)
  30.     {    SplashVisible=0;
  31.         InvalTrash();
  32.     }
  33.  
  34.     WhichButton=GetDownButton();
  35.     /*    Hilite the tool we are going to use.    */
  36.     sel= &ToolButtons[WhichButton];
  37.     if(sel->Function)
  38.     {    HILITEMODE;
  39.         InvertRect(&sel->Prime);
  40.         if(sel->Function<0)
  41.         {    HILITEMODE;
  42.             InvertRect(&sel->Secondary);
  43.         }
  44.     }
  45.  
  46.     ClipEditArea();
  47.     createflag=0;
  48.     switch(sel->Function)    /*    Handle tool actions:    */
  49.     {    case 1:
  50.             elem=CreateNewElement(1,1,NOT_,16);
  51.             elem->Flags |= INVERTED;
  52.             goto movement;
  53.         case -2:
  54.         case -3:
  55.         case -4:
  56.         case 2:
  57.         case 3:
  58.         case 4:
  59.             switch(sel->Function)
  60.             {    case -2:    obtype=NAND;    break;
  61.                 case -3:    obtype=NOR_;    break;
  62.                 case -4:    obtype=NXOR;    break;
  63.                 case  2:    obtype=AND_;    break;
  64.                 case  3:    obtype=OR__;    break;
  65.                 case  4:    obtype=XOR_;    break;
  66.             }
  67.             elem=CreateNewElement(InputSelector,1,obtype,32);
  68.             if((*(char *)(&obtype))=='N')        
  69.                 elem->Flags |= INVERTED;
  70.             goto movement;
  71.         case 8:
  72.         case 10:
  73.             if(sel->Function==8)
  74.                 obtype=RS__;
  75.             else
  76.                 obtype=D___;
  77.  
  78.             elem=CreateNewElement(2,2,obtype,32);
  79.             goto movement;
  80.         case 9:
  81.             elem=CreateNewElement(3,2,JK__,32);
  82.             goto movement;
  83.             break;
  84.         case 11:
  85.             elem=CreateNewElement(1,1,INPT,16);
  86.             elem->Out[0].Data=0;
  87.             elem->InRect=NilRect;
  88.             elem->PrivData=CountElementType(INPT)+1;
  89.             goto movement;
  90.         case 12:
  91.             elem=CreateNewElement(1,1,OUTP,16);
  92.             elem->PrivData=CountElementType(OUTP)+1;
  93.             elem->Out[0].Data=0;
  94.             goto movement;
  95.         case 13:
  96.             elem=CreateNewElement(4,0,HEXD,16);
  97.             goto movement;
  98.         case 14:
  99.             elem=CreateNewElement(0,1,ONE_,16);
  100.             elem->Out[0].Data= -1;
  101.             goto movement;
  102.         case 15:
  103.             elem=CreateNewElement(0,1,ZERO,16);
  104.             elem->Out[0].Data=0;
  105.             goto movement;
  106.         case 16:
  107.             elem=CreateNewElement(0,1,CLOK,16);
  108.             elem->PrivData=0;
  109.             goto movement;
  110. movement:
  111.             if(MoveElementAround(elem,-1)<0)
  112.             {    createflag= -1;
  113.             }
  114.             else
  115.             {    createflag=0;
  116.                 SimEnd=((char *)elem)-SimBase;
  117.             }
  118.             break;
  119.         case 17:    /*    Arrow tool for moving & manipulating elements.    */
  120.             DoArrowTool();
  121.             break;
  122.         case 18:    /*    Scoller tool                                    */
  123.             DoHandScroller();
  124.             break;
  125.         case 19:    /*    Zapper tool for deleting elements and lines.    */
  126.             DoZapperTool();
  127.             break;
  128.     }
  129.     
  130.     if(createflag)
  131.     {    SetTrashRect(&elem->Body);
  132.         InvalTrash();
  133.         CurHeader->Last=SimEnd;
  134.     }
  135.  
  136.     RestoreClipping();
  137.     
  138.     /*    Unhilite selected tool: */
  139.     if(sel->Function)
  140.     {    HILITEMODE;
  141.         InvertRect(&sel->Prime);
  142.         if(sel->Function<0)
  143.         {    HILITEMODE;
  144.             InvertRect(&sel->Secondary);
  145.         }
  146.     }
  147.     
  148.     /*    Reset button function the locked tool.    */
  149.     if(ToolLocks[WhichButton].Function != sel->Function)
  150.     {    InvertButtonTag(WhichButton);
  151.         *sel=ToolLocks[WhichButton];
  152.         InvertButtonTag(WhichButton);
  153.     }
  154. }
  155.